//
//  GestureSectionModel.swift
//  EasePods
//
//  Created by 易先生 on 2024/5/6.
//

import Foundation
import Differentiator
import CRPEarPhone
import RxCocoa
import RxSwift

public struct GestureSectionModel {

    public var eartype: CRPEarType
    public var buttonMode: CRPButtonMode
    public var supprotFuncTypes: [CRPButtonFuncType]
    public var items: [GestureCellViewModel]
    public var selectFuncType: CRPButtonFuncType = .none {
        didSet {
            self.selectFuncTypeRelay.accept(self.selectFuncType)
            self.items.forEach { cellViewModel in
                cellViewModel.isSelect.accept(cellViewModel.buttonFuncType == self.selectFuncType)
            }
        }
    }
    public var selectFuncTypeRelay = BehaviorRelay<CRPButtonFuncType>(value: .none)
}

extension GestureSectionModel: AnimatableSectionModelType {
 
    public typealias Identity = String
    public typealias Item = GestureCellViewModel
    
    public var identity: String {
        return "\(self.eartype.rawValue)-\(self.buttonMode.rawValue)"
    }
    
    public init(original: GestureSectionModel, items: [GestureCellViewModel]) {
        self = original
        self.items = items
    }
}


